import common from '../../common/common';

export default {
  namespaced: true,
  state: {
    title: '首页',
    isBack: false,
    homedata: {},
    recordList:[],
    sidebarList: []
  },
  mutations: {
    SET_VALUE (state, {title = state.title, isBack = state.isBack}) {
      state.title = title;
      state.isBack = isBack;
    },
    SET_LIST (state, payload) {
      state.movieList = payload.movies;
    },
    HOME_DATA (state, payload) {
      state.homedata = payload;
    },
    SET_SIDEBAR (state, {list}) {
      state.sidebarList = list;
    }
  },
  actions: {
    FETCH ({ commit }) {
      return common.req('getMovies', {}, function (data, def){
        if(data){
          return commit('SET_LIST', data);
        }
        //fail
        return def.resolve({msg:'fail'});
      }, false);
    },
    GETLIST ({commit}) {
      return common.api('getspalist', {a:111}).then(data=>{
        // console.log(data);
        commit('SET_LIST', {
          movies:data.data
        });
        return data.data;
      });
    }
  }
};
